<?php
/**
 * 类说明 :
 * User: 刘明昆
 * Date: 2019-1-28
 * Time: 10:34
 */

/**
 * 对象转换数组
 */
function object_to_array($obj){
    if(is_array($obj)){
        return $obj;
    }
    $_arr = is_object($obj)? get_object_vars($obj) :$obj;
    foreach ($_arr as $key => $val){
        $val=(is_array($val)) || is_object($val) ? object_to_array($val) :$val;
        $arr[$key] = $val;
    }

    return $arr;
}
/**
 * 把对象转化为json
 */
function object_to_json($obj){
    $arr2=object_to_array($obj);//先把对象转化为数组
    return json_encode($arr2);
}